package com.sdtele.tta.operation;



import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sdtele.tta.dac.Dac;
import com.sdtele.tta.models.JsonRequest;
import com.sdtele.tta.models.JsonResponse;
import com.sdtele.tta.models.Task;
import com.sdtele.tta.models.User;
import com.sdtele.tta.models.VoteTask;



public class OperationGetTask extends Operation {
	
	public JsonResponse handle(JsonRequest jsonRequest) {
		System.out.println("OperationLogin:req="+jsonRequest);
		JsonResponse jres = new JsonResponse();
		User curUser = (User) request.getSession().getAttribute("user");
		Map<String,String> indexMap=new HashMap<String,String>();
		List<Task> newTask=Dac.getInstance().getTaskbyUser(curUser.getId());
		List<Task> getTaskbyDeadline=Dac.getInstance().getTaskbyDeadline(curUser.getId());
		List<Task> getTaskbyState=Dac.getInstance().getTaskbyState(curUser.getId());
		List<Task> getTaskupDeadline=Dac.getInstance().getTaskupDeadline(curUser.getId());
		List<Task> getTaskbyCompletion=Dac.getInstance().getTaskbyCompletion(curUser.getId());
		List<Task> getTaskbyWeek=Dac.getInstance().getTaskbyWeek(curUser.getId());
		List<Task> getTaskbyReader=Dac.getInstance().getTaskbyReader(curUser.getId());
		List<VoteTask> getVote=Dac.getInstance().getVote(curUser.getId());
	
		if(newTask==null) {
			 indexMap.put("newTask", String.valueOf(0));
		}else {
			 indexMap.put("newTask", String.valueOf(newTask.size()));
			 
		}
		
		if(getTaskbyDeadline==null) {
			 indexMap.put("getTaskbyDeadline", String.valueOf(0));
		}else {
			 indexMap.put("getTaskbyDeadline", String.valueOf(getTaskbyDeadline.size()));
			 
		}
		
		if(getTaskbyState==null) {
			 indexMap.put("getTaskbyState", String.valueOf(0));
		}else {
			 indexMap.put("getTaskbyState", String.valueOf(getTaskbyState.size()));
			 
		}
		
		if(getTaskupDeadline==null) {
			 indexMap.put("getTaskupDeadline", String.valueOf(0));
		}else {
			 indexMap.put("getTaskupDeadline", String.valueOf(getTaskupDeadline.size()));
			 
		}
		
		if(getTaskbyCompletion==null) {
			 indexMap.put("getTaskbyCompletion", String.valueOf(0));
		}else {
			 indexMap.put("getTaskbyCompletion", String.valueOf(getTaskbyCompletion.size()));
			 
		}
		
		if(getTaskbyWeek==null) {
			 indexMap.put("getTaskbyWeek", String.valueOf(0));
		}else {
			 indexMap.put("getTaskbyWeek", String.valueOf(getTaskbyWeek.size()));
			 
		}
		
		if(getTaskbyReader==null) {
			 indexMap.put("getTaskbyReader", String.valueOf(0));
		}else {
			 indexMap.put("getTaskbyReader", String.valueOf(getTaskbyReader.size()));
			 
		}
		
		if(getVote==null) {
			 indexMap.put("getVote", String.valueOf(0));
		}else {
			 indexMap.put("getVote", String.valueOf(getVote.size()));
			 
		}
		
		if(indexMap.size()>0) {
			jres.setStatus(0);
			jres.setMessage("工作台map获取成功");
			jres.setEntity(indexMap);
		}else {
			jres.setStatus(1);
			jres.setMessage("工作台map获取失败");
			
		}
		return jres;
	}
   
   
}